﻿using Comm100.Framework.Domain.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using Bot.Domain.Bo;
using Castle.Windsor;
using Newtonsoft.Json;

namespace Bot.Domain.Categories.Service
{
    public class WebhookDomainService : IWebhookDomainService
    {
        private IWindsorContainer _container;
        private readonly IRepository<Guid, Webhook> _repository;

        public WebhookDomainService(IRepository<Guid, Webhook> repository, IWindsorContainer container)
        {
            this._repository = repository;
            this._container = container;
        }

        public Webhook Create(Webhook category)
        {
            return _repository.Create(category);
        }

        public Webhook Get(Guid id)
        {
            return _repository.Get(id);
        }

        public Webhook Update(WebhookUpdateBo bo)
        {
            Webhook webhook = _repository.Get(bo.Id);
            webhook.Id = bo.Id;
            webhook.URL = bo.URL;
            webhook.Header = JsonConvert.SerializeObject(bo.Headers);

            _repository.Update(webhook);

            return webhook;

        }

        public IEnumerable<Webhook> List()
        {
            return _repository.ListAll();
        }

        public void Delete(Guid id)
        {
            Webhook webhook = _repository.Get(id);

            _repository.Delete(webhook);

        }
    }
}
